Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: proper FW revision offline error handling #16859

Merged
merged 3 commits into from
Feb 6, 2025

Conversation

Lemonexe
Copy link
Contributor

@Lemonexe Lemonexe commented Feb 5, 2025

Description

  • connect: fix issue with identifying network errors during FW revision check
    • so that they are correctly identified as such also in react native (and not lumped as an other-error)
    • similar to #15707 which fixed it for Desktop
  • do not report cannot-perform-check-offline to Sentry (does not make sense to report such a thing!)
    • rare occurence on mobile (example event), so disable it to reduce noise
    • never happens on desktop. Still, the code should reflect we don't want it to

❗ root cause issue still stands - why connect does not load the releases.json and identifiy the revision there? But given the observations, it's now not necessarily mobile only! The problem could very well be on desktop too, but invisible, because on desktop, fetch error will be correctly identified as offline error, and that's not seen in Sentry. Need to investigate further..

🤔 💭 why are there offline errors on mobile, but never on desktop? Idk! Maybe because different Sentry SDK? In web/desktop SDK, it immediately sends an event to ingest, but you're offline so it never arrives. I guess mobile sends it later, when you are connected again.

Related Issue

Resolve #16725

Copy link

coderabbitai bot commented Feb 5, 2025

Walkthrough

The pull request refactors error handling in multiple firmware revision check modules. In the connect package, the existing inline error checks are replaced with dedicated functions to detect network errors in both Node.js and React Native environments. A new wrapper function consolidates these checks. In the suite components and hooks, the error reporting mechanism now imports configuration for error scenarios, allowing it to conditionally bypass reporting based on the defined shouldReport property. Additionally, updates in the firmware constants and configurations relax type restrictions around soft warnings, permitting errors to be marked as non-reportable. Overall, the changes aim to streamline and centralize error handling and reporting behavior for firmware checks.

Assessment against linked issues

Objective Addressed Explanation
FW revision check parses releases.json correctly (#16725) No modifications were made to the JSON parsing logic; only error handling was refined.

Suggested labels

bug, release

Suggested reviewers

  • mroz22
  • komret
  • szymonlesisz
  • marekrjpolak

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

github-actions bot commented Feb 5, 2025

🚀 Expo preview is ready!

  • Project → trezor-suite-preview
  • Platforms → android, ios
  • Scheme → trezorsuitelite
  • Runtime Version → 24
  • More info

Learn more about 𝝠 Expo Github Action

@Lemonexe Lemonexe marked this pull request as ready for review February 6, 2025 08:16
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/connect/src/device/checkFirmwareRevision.ts (1)

9-12: Consider using constants for error names and messages.

The implementation correctly identifies network errors across different environments. Consider extracting the error names and messages into constants for better maintainability.

+const NODE_JS_NETWORK_ERRORS = ['FetchError', 'AbortError'] as const;
+const RN_NETWORK_ERROR_NAME = 'TypeError';
+const RN_NETWORK_ERROR_MESSAGE = 'Network request failed';

-const isNodeJSNetworkError = (e: Error) => ['FetchError', 'AbortError'].includes(e.name);
+const isNodeJSNetworkError = (e: Error) => NODE_JS_NETWORK_ERRORS.includes(e.name as typeof NODE_JS_NETWORK_ERRORS[number]);

-const isReactNativeNetworkError = (e: Error) =>
-    e.name === 'TypeError' && e.message.includes('Network request failed');
+const isReactNativeNetworkError = (e: Error) =>
+    e.name === RN_NETWORK_ERROR_NAME && e.message.includes(RN_NETWORK_ERROR_MESSAGE);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 126ad48 and fa3f73e.

📒 Files selected for processing (5)
  • packages/connect/src/device/checkFirmwareRevision.ts (2 hunks)
  • packages/suite/src/components/suite/SecurityCheck/useReportDeviceCompromised.ts (2 hunks)
  • packages/suite/src/constants/suite/firmware.ts (2 hunks)
  • suite-native/device/src/config/firmware.ts (2 hunks)
  • suite-native/device/src/hooks/useReportDeviceCompromised.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: run_android_e2e_tests
  • GitHub Check: run_android_e2e_tests
  • GitHub Check: run_android_e2e_tests
  • GitHub Check: run_android_e2e_tests
  • GitHub Check: run_android_e2e_tests
  • GitHub Check: run_android_e2e_tests
  • GitHub Check: run_android_e2e_tests
  • GitHub Check: run_android_e2e_tests
  • GitHub Check: run_android_e2e_tests
  • GitHub Check: run_android_e2e_tests
🔇 Additional comments (10)
suite-native/device/src/config/firmware.ts (2)

9-9: LGTM! Type definition updated to support flexible error reporting.

The change to allow shouldReport to be either true or false provides the necessary flexibility to control error reporting behavior.


19-19: LGTM! Disabled reporting for offline errors.

This change aligns with the PR objectives to stop reporting cannot-perform-check-offline errors to Sentry, as these are expected occurrences that don't warrant reporting.

suite-native/device/src/hooks/useReportDeviceCompromised.ts (2)

9-9: LGTM! Clean import of error scenarios configuration.

The import statement is well-placed and maintains code organization.


36-36: LGTM! Added conditional check for error reporting.

The condition correctly uses the configuration to prevent reporting of errors marked with shouldReport: false.

packages/suite/src/constants/suite/firmware.ts (2)

14-14: LGTM! Type definition inherits base behavior.

The SoftWarningBehavior type now correctly inherits the shouldReport property from BehaviorBaseType, maintaining type safety while allowing flexible reporting behavior.


27-27: LGTM! Consistent error reporting configuration.

The configuration matches the native implementation, ensuring consistent behavior across platforms.

packages/suite/src/components/suite/SecurityCheck/useReportDeviceCompromised.ts (2)

8-8: LGTM! Clean import of error scenarios configurations.

The import statement efficiently combines both revision and hash check scenarios.


64-64: LGTM! Consistent error reporting control.

The condition matches the native implementation, ensuring consistent behavior while maintaining the additional hash check functionality.

packages/connect/src/device/checkFirmwareRevision.ts (2)

107-111: LGTM! Error handling improvements look good.

The changes correctly identify network errors and return appropriate error types, aligning with the PR objectives to improve error handling in React Native environment.


13-25: Verify test coverage for network error detection.

The network error detection logic is crucial for proper error handling. Please ensure it's covered by unit tests.

✅ Verification successful

🏁 Script executed:

#!/bin/bash
# Description: Check test coverage for network error detection

# Search for test files related to checkFirmwareRevision
fd -e test.ts -e spec.ts checkFirmwareRevision

# Search for test cases covering network errors
rg -A 5 -B 5 "isNetworkError|isNodeJSNetworkError|isReactNativeNetworkError" --type ts

Length of output: 3655


🏁 Script executed:

#!/bin/bash
# Output the contents of the test file for checkFirmwareRevision to verify network error tests
cat packages/connect/src/device/__tests__/checkFirmwareRevision.test.ts

Length of output: 5500


Test coverage for network error detection verified.

  • The unit tests in packages/connect/src/device/__tests__/checkFirmwareRevision.test.ts include scenarios that throw a FetchError to simulate network errors.
  • The test verifies that when a network error is thrown, the function returns the 'cannot-perform-check-offline' error, confirming that the network error detection logic is correctly covered.

Copy link
Contributor

@peter-sanderson peter-sanderson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

few nits solved over call

@Lemonexe Lemonexe force-pushed the fix/native-offline-error-in-connect branch from fa3f73e to 1ba6a1b Compare February 6, 2025 14:08
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/connect/src/device/checkFirmwareRevision.ts (1)

9-11: LGTM! Consider extracting the error message check to a constant.

The network error detection functions are well-implemented for both Node.js and React Native environments.

Consider extracting the error message to a constant for better maintainability:

+const REACT_NATIVE_NETWORK_ERROR_MESSAGE = 'Network request failed';
 const isReactNativeNetworkError = (e: Error) =>
-    e.name === 'TypeError' && e.message.includes('Network request failed');
+    e.name === 'TypeError' && e.message.includes(REACT_NATIVE_NETWORK_ERROR_MESSAGE);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fa3f73e and 1ba6a1b.

📒 Files selected for processing (5)
  • packages/connect/src/device/checkFirmwareRevision.ts (2 hunks)
  • packages/suite/src/components/suite/SecurityCheck/useReportDeviceCompromised.ts (2 hunks)
  • packages/suite/src/constants/suite/firmware.ts (2 hunks)
  • suite-native/device/src/config/firmware.ts (2 hunks)
  • suite-native/device/src/hooks/useReportDeviceCompromised.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • suite-native/device/src/hooks/useReportDeviceCompromised.ts
  • packages/suite/src/constants/suite/firmware.ts
  • suite-native/device/src/config/firmware.ts
⏰ Context from checks skipped due to timeout of 90000ms (15)
  • GitHub Check: PR-check / node-authorizeCoinjoin cancelCoinjoinAuthorization passphrase unlockPath setBusy checkFirmwareAuthenticity keepSession cancel.test info.test resetDevice-api
  • GitHub Check: PR-check / web-override init-api-flaky
  • GitHub Check: PR-check / node-override init-api-flaky
  • GitHub Check: PR-check / web-authorizeCoinjoin cancelCoinjoinAuthorization passphrase unlockPath setBusy checkFirmwareAuthenticity keepSession cancel.test info.test resetDevice-api
  • GitHub Check: build-deploy
  • GitHub Check: run-desktop-tests (@group=wallet, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: EAS Update
  • GitHub Check: run-desktop-tests (@group=settings, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: run-desktop-tests (@group=device-management, trezor-user-env-unix)
  • GitHub Check: Setup and Cache Dependencies
  • GitHub Check: prepare_android_test_app
  • GitHub Check: build-web
  • GitHub Check: run-desktop-tests (@group=suite, trezor-user-env-unix)
  • GitHub Check: build-web
  • GitHub Check: Analyze with CodeQL (javascript)
🔇 Additional comments (4)
packages/suite/src/components/suite/SecurityCheck/useReportDeviceCompromised.ts (2)

8-8: LGTM!

The addition of revisionCheckErrorScenarios import aligns with the PR objectives to improve error handling.


63-63: LGTM! Verify error reporting consistency.

The addition of the shouldReport check aligns with the PR objectives and follows the same pattern as useReportHashCheck.

Run the following script to verify consistent error reporting patterns:

✅ Verification successful

🏁 Script executed:

#!/bin/bash
# Description: Verify that error reporting patterns are consistent across the codebase.

# Test: Search for similar error reporting patterns. Expect: Consistent usage of shouldReport.
rg -A 5 $'shouldReport.*reportCheckFail'

Length of output: 41


I'll generate an additional script to inspect the error reporting context in both files. This script will print a snippet from useReportDeviceCompromised.ts around the check and try to locate and show similar context from useReportHashCheck.ts to verify that the error reporting pattern is consistent.


🏁 Script executed:

#!/bin/bash
# Print a snippet from useReportDeviceCompromised.ts to inspect the error reporting check.
echo "=== useReportDeviceCompromised.ts (lines 55-75) ==="
sed -n '55,75p' packages/suite/src/components/suite/SecurityCheck/useReportDeviceCompromised.ts

echo ""
echo "=== Searching for useReportHashCheck.ts and printing its context for 'shouldReport' ==="
# Locate the file(s) containing 'useReportHashCheck.ts'
fd "useReportHashCheck.ts" .

# For every found file, print a snippet around the occurrence of 'shouldReport'
for file in $(fd "useReportHashCheck.ts" .); do
  echo ""
  echo "Snippet from $file:"
  rg -n -C 5 "shouldReport" "$file"
done

Length of output: 1240


I'll generate another script to print the complete context of the useReportHashCheck function from the file so we can verify that the error reporting pattern (and its conditional checks) is consistent with the revision check logic.


🏁 Script executed:

#!/bin/bash
# Print the complete context of the useReportHashCheck function for further inspection.
sed -n '/const useReportHashCheck =/,$p' packages/suite/src/components/suite/SecurityCheck/useReportDeviceCompromised.ts

Length of output: 1733


Error reporting patterns are consistent across hooks.
Both useReportRevisionCheck and useReportHashCheck use a shouldReport check to conditionally trigger error reporting, ensuring that errors are only reported when appropriate. The implementation in useReportRevisionCheck mirrors the pattern seen in useReportHashCheck, providing consistent behavior in handling error scenarios.

packages/connect/src/device/checkFirmwareRevision.ts (2)

19-23: LGTM! Well-documented and type-safe implementation.

The isNetworkError function effectively combines checks for both environments with proper type safety.


105-108: LGTM! Improved error handling precision.

The error handling now correctly identifies network errors across different environments, which directly addresses the PR objectives.

@Lemonexe Lemonexe merged commit 41c1919 into develop Feb 6, 2025
74 checks passed
@Lemonexe Lemonexe deleted the fix/native-offline-error-in-connect branch February 6, 2025 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FW revision check does not parse the releases.json correctly
2 participants